package cn.catsdad.base.entity;

import cn.catsdad.util.SnowflakeIdUtil;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * @author xuyl
 * @version 1.0 2024/6/23
 */
@Data
@Accessors(chain = true)
@MappedSuperclass
public abstract class BaseEntity implements Serializable {

    /**
     * 序列换版本标识，
     * 使用@Serial修饰时会在项目编译阶段对此字段进行检查
     */
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 初始化填充雪花id
     */
    @Id
    private Long id = SnowflakeIdUtil.getSnowflakeId();

    /**
     * 创建时间
     */
    @CreatedDate
    private Date createdTime;

    /**
     * 创建人id
     */
    @CreatedBy
    private long creatorId;

    /**
     * 修改时间
     */
    @LastModifiedDate
    private Date ModifiedTime;

    /**
     * 修改人id
     */
    @LastModifiedBy
    private long modifierId;

    /**
     * 假删字段
     */
    private Boolean isDeleted = false;
}
